package pl.perseus.service.account;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import pl.perseus.dao.IAccountDao;
import pl.perseus.model.Account;
import pl.perseus.model.User;

@Service
@Transactional
public class AccountService implements IAccountService {

	@Autowired
	IAccountDao accountDao;
	
	@Override
	public Account insertAccount(Account account){
		return accountDao.insertAccount(account);
	}
	
	@Override
	public Account getAccountForUser(User user) {
		return accountDao.getAccountByUser(user);
	}
	
	@Override
	public List<Account> getAllAccounts(){
		return accountDao.getAllAccounts();
	}
	
	@Override
	public boolean isAdmin(Account account){
		String role = account.getAccountname().trim().toLowerCase();
		return role.equals(getAdmin());
	}
	
	@Override
	public boolean isTeacher(Account account){
		String role = account.getAccountname().trim().toLowerCase();
		return role.equals(getTeacher());
	}
	
	@Override
	public String getAdmin(){
		return "admin";
	}
	
	@Override
	public String getTeacher(){
		return "user";
	}
	
}
